/** 数据表格 */
cc.Class({
    extends: cc.Component,

    properties: {
        /** 标题文字 */
        hd_text:[cc.String],
        /** 绑定的key */
        bind_key:[cc.String],
        /** 列宽度 */
        col_width:[cc.Integer],
        /** 行高 */
        line_height:cc.Integer,
        /** 行背景颜色 */
        line_color:[cc.Color],
        /** 数据 */
        _data:Object,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        if(!this.line_height) this.line_height = 16;
        if(!this.line_color) this.line_color = [new cc.Color(), new cc.Color()]
        let w = 0;
        for(let i=0;i<this.hd_text.length;i++){
            if(!this.col_width[i]) this.col_width[i] = 50;
            let nd = new cc.Node();
            nd.x = w;
            nd.y = 8;
            nd.width = this.col_width[i];
            nd.height = this.line_height/2;
            nd.anchorX = 0;
            w += this.col_width[i];
            let lb = nd.addComponent(cc.Label);
            lb.enableWrapText = false;
            lb.fontSize = 12;
            lb.lineHeight = 16;
            lb.overflow = cc.Label.Overflow.CLAMP;
            lb.string = this.hd_text[i];
            nd.parent = this.node;
        }
    },

    start () {

    },

    // update (dt) {},

    /** 设置数据 */
    bindData(da){
        for(let i=0;i<da.length;i++){
            let w = 0;
            for(let j=0;j<this.bind_key.length;j++){
                let nd = new cc.Node();
                nd.x = w;
                nd.y = 8;
                nd.width = this.col_width[i];
                nd.height = this.line_height/2;
                nd.anchorX = 0;
                w += this.col_width[i];
                let lb = nd.addComponent(cc.Label);
                lb.enableWrapText = false;
                lb.fontSize = 12;
                lb.lineHeight = 16;
                lb.overflow = cc.Label.Overflow.CLAMP;
                lb.string = this.hd_text[i];
                nd.parent = this.node;
            }
        }
    }
});
